package A.reflection3;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * 通过反射越过泛型检查
 */
public class Demo {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        ArrayList<String> strList = new ArrayList<>();
        strList.add("a");
        strList.add("b");

        Class<? extends ArrayList> listClass = strList.getClass();
        Method m = listClass.getMethod("add", Object.class);
        m.invoke(strList,100);

        for (Object obj : strList){
            System.out.println(obj);
        }
    }
}
